package com.tszs.filter;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

@WebFilter("/pc/admin/*")
public class AdminLoginFilter implements Filter {

	@Override
	public void destroy() {
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest request1 = (HttpServletRequest) request;
		String url = request1.getRequestURL().toString();
		if (url.endsWith("index.jsp")||url.endsWith("login.jsp")||url.endsWith("login.do")||null!=request1.getSession().getAttribute("aId")) {
			chain.doFilter(request, response);
		} else {
			/*response1.sendRedirect(request1.getContextPath() + "/login.jsp");*/
			PrintWriter out = response.getWriter();
		    out.println("<html>");    
		    out.println("<script>");    
		    out.println("window.open ('"+request1.getContextPath()+"/login.jsp','_top')");    
		    out.println("</script>");    
		    out.println("</html>");  
		}
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	}

}
